<template>
	<view class="">
		<view v-if="activityList.length > 0">
			<view v-for="(item, index) in activityList" :key="item.activityId">
				<activity-cell 
				:activityType="item.activityType" 
				:activityTitle="item.activityName"
				:applyCount="item.inventedSalesNumber"
				:isReferralBonuses = "item.isReferralBonuses"
				:finishTime="item.timeEnd"
				:activityId="item.activityId"
				:activityUrl="item.coverImage | imageUrl"
				></activity-cell>
			</view>
			<u-loadmore :status="loadingStatus" @loadmore="clickloadmore"></u-loadmore>
		</view>
		<u-empty v-if="activityList.length == 0" mode="list" marginTop="160"></u-empty>
	</view>
</template>

<script>
	import activityCell from '../../components/activity/activity-cell.vue'
	import {apiActivityList} from '../../common/api.js'
	import GLOBAL_CONFIG from '@/common/config';
	export default {
		components: {
			activityCell
		},
		data() {

			return {
				pageNo : 1,
				loadingStatus: 'loading',
				activityList: []
			}
		},
		filters:{
			imageUrl(url) {
				return GLOBAL_CONFIG.yxBaseImageUrl + url;
			},
		},
		onLoad() {
			this.getData();
		},
		methods: {
			getData() {
				apiActivityList({
					tenantId : this.$store.state.user.tenantCodede,
					applicableUnitNo : this.$store.state.user.deptId,
					memberNo : this.$store.state.user.userInfo.customerId,
					pageNo : this.pageNo,
					pageSize: 10,
				}).then(res => {
					if (this.pageNo == 1) {
						this.activityList = [];
						this.pageNo++;
						// uni.stopPullDownRefresh();
					
						this.loadingStatus = 'loadmore';
					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.pageNo++;
					
							this.loadingStatus = 'loadmore';
						} else {
					
							this.loadingStatus = 'nomore';
						}
					}
					
					if (!uni.$u.test.isEmpty(res)) {
						this.activityList = this.activityList.concat(res);
					}
				})
			},
			clickloadmore() {
				this.getData();
				this.showloading = true;
				this.loadingStatus = 'loading';
			}
		},
		onPullDownRefresh() {
			this.pageNo = 1;
			this.getData();
		},
		
		onReachBottom() {
			this.getData();
			this.showloading = true;
			this.loadingStatus = 'loading';
		}
	}
</script>

<style>
</style>
